package com.zhongfl.crm.model.boss;

import com.zhongfl.crm.enums.boss.WorkOrderStatus;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;

/**
 * 工单明细对象
 *
 * @author wang.yuchuan
 * @date 2018/5/21
 */
@Getter
@Setter
public class WorkOrderDetailsResult implements Serializable {
    private static final long serialVersionUID = -582767974110019307L;

    /**
     * 订单信息
     */
    private Order order;

    /**
     * 工单信息
     */
    private WorkOrder workOrder;

    /**
     * 工单任务清单
     */
    private List<WorkOrderTask> taskList;

    /**
     * 工单操作日志
     */
    private List<CommonLog> workOrderLogs;

    /**
     * 工单结算单
     */
    private WorkOrderSettle workOrderSettle;

    /**
     * 返库工单对应的原工单(先这样命名吧,哎)
     */
    private WorkOrderSettle backWorkOrderSettle;

    private boolean hasSettled;

    public boolean getHasSettled() {
        if (Objects.isNull(workOrderSettle)) {
            return false;
        }
        return true;
    }

    /**
     * 工单相关人员信息
     */
    private WorkOrderStaffs workOrderStaffs;

    private boolean allowRedoSettle;

    public boolean getAllowRedoSettle() {
        if (Objects.isNull(workOrderStaffs)) {
            return false;
        }
        return workOrderStaffs.getIsReceiveAmibaManager() && getHasSettled();
    }

    /**
     * 是否允许返库
     */
    private boolean allowBack;

    public boolean getAllowBack() {
        if (Objects.isNull(workOrder)) {
            return false;
        }
        return workOrder.getStatus().equals(WorkOrderStatus.COMPLETED) || workOrder.getStatus().equals(WorkOrderStatus.SETTLED);
    }
}
